import { INotificationUtil, NotificationParams } from '@ibiz-template/runtime';
import { ElNotification } from 'element-plus';

/**
 * 在界面右上角显示可关闭的全局通知
 *
 * @author chitanda
 * @date 2022-08-17 16:08:26
 * @export
 * @class NotificationUtil
 * @implements {INotificationUtil}
 */
export class NotificationUtil implements INotificationUtil {
  info(params: NotificationParams): void {
    const duration = params.duration ? params.duration * 1000 : 4500;
    ElNotification({
      title: params.title,
      message: params.desc,
      type: 'info',
      duration,
    });
  }

  success(params: NotificationParams): void {
    const duration = params.duration ? params.duration * 1000 : 4500;
    ElNotification({
      title: params.title,
      message: params.desc,
      type: 'success',
      duration,
    });
  }

  warning(params: NotificationParams): void {
    const duration = params.duration ? params.duration * 1000 : 4500;
    ElNotification({
      title: params.title,
      message: params.desc,
      type: 'warning',
      duration,
    });
  }

  error(params: NotificationParams): void {
    const duration = params.duration ? params.duration * 1000 : 4500;
    ElNotification({
      title: params.title,
      message: params.desc,
      type: 'error',
      duration,
    });
  }
}
